#include "doublespinbox.h"
#include "ui_DoubleSpinBox.h"

DoubleSpinBox::DoubleSpinBox(QWidget *parent) : QWidget(parent), ui(new Ui::DoubleSpinBox) {
    ui->setupUi(this);
//    this->setStyleSheet(QString::fromLocal8Bit("QWidget{border-radius: 5px; border: 1px solid rgb(214, 214, 214);}\n"
//                                               "QWidget:hover{border: 1px solid #409EFF;}"
//                                               "QPushButton{border: none;background-color: rgb(245, 247, 250);}"
//                                               "QPushButton::hover{color: #409EFF;}"
//                                               "QDoubleSpinBox{color: #606266;font: 57 16pt 思源黑体 CN Medium;border: none;}"));
}

DoubleSpinBox::~DoubleSpinBox() {
    delete ui;
}

QString DoubleSpinBox::prefix() const {
    return ui->doubleSpinBox->prefix();
}

void DoubleSpinBox::setPrefix(const QString &prefix){
    ui->doubleSpinBox->setPrefix(prefix);
}

QString DoubleSpinBox::suffix() const {
    return ui->doubleSpinBox->suffix();
}

void DoubleSpinBox::setSuffix(const QString &suffix) {
    ui->doubleSpinBox->setSuffix(suffix);
}

QString DoubleSpinBox::cleanText() const {
    return ui->doubleSpinBox->cleanText();
}

double DoubleSpinBox::singleStep() const {
    return ui->doubleSpinBox->singleStep();
}

void DoubleSpinBox::setSingleStep(double val) {
    ui->doubleSpinBox->setSingleStep(val);
}

double DoubleSpinBox::minimum() const {
    return ui->doubleSpinBox->minimum();
}

void DoubleSpinBox::setMinimum(double min) {
    ui->doubleSpinBox->setMinimum(min);
}

double DoubleSpinBox::maximum() const {
    return ui->doubleSpinBox->maximum();
}

void DoubleSpinBox::setMaximum(double max) {
    ui->doubleSpinBox->setMaximum(max);
}

void DoubleSpinBox::setRange(double min, double max) {
    ui->doubleSpinBox->setRange(min, max);
}

int DoubleSpinBox::decimals() const {
    return ui->doubleSpinBox->decimals();
}

void DoubleSpinBox::setDecimals(int prec) {
    ui->doubleSpinBox->setDecimals(prec);
}

QValidator::State DoubleSpinBox::validate(QString &input, int &pos) const {
    return ui->doubleSpinBox->validate(input, pos);
}

double DoubleSpinBox::valueFromText(const QString &text) const {
    return ui->doubleSpinBox->valueFromText(text);
}

QString DoubleSpinBox::textFromValue(double val) const {
    return ui->doubleSpinBox->textFromValue(val);
}

double DoubleSpinBox::value() const {
    return ui->doubleSpinBox->value();
}

void DoubleSpinBox::setValue(double value) {
    ui->doubleSpinBox->setValue(value);
}

void DoubleSpinBox::on_addButton_clicked() {
    double val = ui->doubleSpinBox->value() + ui->doubleSpinBox->singleStep();
    double maxVal = ui->doubleSpinBox->maximum();
    val = val <= maxVal ? val : maxVal;
    ui->doubleSpinBox->setValue(val);
}

void DoubleSpinBox::on_subButton_clicked() {
    double val = ui->doubleSpinBox->value() - ui->doubleSpinBox->singleStep();
    double minVal = ui->doubleSpinBox->minimum();
    val = val >= minVal ? val : minVal;
    ui->doubleSpinBox->setValue(val);
}

void DoubleSpinBox::on_doubleSpinBox_textChanged(const QString &arg1) {
    emit textChanged(arg1);
}

void DoubleSpinBox::on_doubleSpinBox_valueChanged(double arg1) {
    emit valueChanged(arg1);
}
